package core.controller.cmds;

import core.controller.CommandController;
import core.dal.OperatorFunctionality;
import exceptions.UserNotFoundException;

public class ChangePasswordCMD implements ICmd{

	final String level = "Operator";
	OperatorFunctionality functionality;
	ICmd nextCMD;
	CommandController cc;
	
	public ChangePasswordCMD(CommandController commandController, OperatorFunctionality oF){
		this.cc = commandController;
		functionality = oF;
	}	
	
	@Override
	public void setNextCmd(ICmd nextCmd) {
		nextCMD = nextCmd;
		
	}

	@Override
	public void execute(String cmd) {
		if (cmd.equals("changePass")){
			String newpass = cc.getTUI().getInput();
			
			try {
				functionality.changePassword(cc.getCurrentUser().getOprId(), newpass);
				cc.getTUI().showOutput("PASSWORD CHANGED");
			} catch (UserNotFoundException e) {
				System.out.println(e.getMessage());
			}

			
		}
		
		if (nextCMD != null) {
			nextCMD.execute(cmd);
		}
	}

	@Override
	public String getInfo() {
		return "changePass - Change your password";
		
	}

	@Override
	public String getLevel() {
		return this.level;
		
	}
}
